package com.itheima.springbootwebtlias.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
//3.配置过滤器，设置过滤的路径 /*表示过滤所有请求
//@WebFilter(urlPatterns = "/*")
//1.自定义过滤器类，实现Filter接口
public class MyFilter implements Filter {

    //2.重写核心的过滤方法
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse  response = (HttpServletResponse) servletResponse;
        log.info("拦截请求。。。。。。");

        //小区大门：拦截所有请求，放行操作
        filterChain.doFilter(servletRequest,servletResponse);

        //处理响应结果
        response.setStatus(404);

        log.info("拦截响应。。。。。。");
    }
}
